﻿var zombies = zombies || {};
var windowURL = window.URL || window.webkitURL;

zombies.Profile = function () {
    var self = this;

    self.Loaded = ko.observable(false);

    self.Avatar = ko.observable("../../Advertise/DefaultAssets/NoAvatar.gif");
    self.FullName = ko.observable();
    self.Gender = ko.observable();
    self.Birthday = ko.observable();
    self.CMND = ko.observable();
    self.Email = ko.observable();
    self.Address = ko.observable();
    self.Phone = ko.observable();
    self.Point = ko.observable();
    self.Level = ko.observable();
};

var load = function (id) {

    $.ajax({
        type: "GET",
        url: "/api/MemberProfile/GetMemProfile/" + id,
        contentType: "application/json",
        dataType: 'json'
    }).done(function (item) {
        if (item.Avatar != null && item.Avatar != '') {
            memProfileViewModel.Avatar('../' + item.Avatar);
        }
        memProfileViewModel.FullName(item.FirstName + ' ' + item.LastName);
        memProfileViewModel.Gender(item.Gender == 'Male' ? 'Nam' : 'Nữ');
        memProfileViewModel.Birthday(moment(item.Birthday).format('LLL'));
        memProfileViewModel.CMND(item.CMND);
        memProfileViewModel.Email(item.Email);
        memProfileViewModel.Address(item.Address);
        memProfileViewModel.Phone(item.Phone);
        memProfileViewModel.Point(item.Point);
        memProfileViewModel.Level(item.Level);
        memProfileViewModel.Loaded(true);
    });
};

var memProfileViewModel;
var memid_tmp = document.URL.split('/').pop();
$(document).ready(function () {
    memProfileViewModel = new zombies.Profile();
    load(memid_tmp);
    ko.applyBindings(memProfileViewModel, document.getElementById("my-container"));
});